package servicios;

import java.util.ArrayList;
import java.util.List;

import dominio.Criterio;

import persistencia.CriterioDAO;
import persistencia.PersistentException;

public class ServiciosCriterio  extends BusinessService{

	public static List<Object> getCriterios() throws GenericBusinessException {
		try {
			CriterioDAO cd=new CriterioDAO();
			List<Object> criterios=cd.selectAll();
			return criterios;
		} catch (PersistentException e) {
			 throw new SystemException(e.getMessage());
		}
	}



	@SuppressWarnings("unchecked")
	public static List<Object> getPlanProduccion() throws GenericBusinessException {
		try {
			int planProduccion=CriterioDAO.getCriterio();
			CriterioDAO cd=new CriterioDAO();
			Criterio criterio=cd.getCriterio(planProduccion);
			List<Object> retorno=new ArrayList<Object>();
			Class clase=Class.forName(criterio.getClase());
			PlanProduccion order=(PlanProduccion)clase.newInstance();
			retorno=order.ejecutar();	
			return retorno;
		} catch (PersistentException e) {
			throw new SystemException(e.getMessage());
		} catch (ClassNotFoundException e) {
			throw new SystemException(e.getMessage());
		} catch (InstantiationException e) {
			throw new SystemException(e.getMessage());
		} catch (IllegalAccessException e) {
			throw new SystemException(e.getMessage());
		}
	}
	
	public static void setCriterio(int i)  throws GenericBusinessException {
		try{
			CriterioDAO.setCriterio(i);
		} catch (PersistentException e) {
			 throw new SystemException(e.getMessage());
		}
	}

}
